package mq

/**
 * 控制器接口
 */
type Ctrl interface {
	DoBefore(ctx *Context) error
	Action(ctx *Context)
	DoAfter(ctx *Context) error
	AddFilter(filter Filter)
	Filters() []Filter
}

func NewBaseCtrl() *BaseCtrl {
	ctrl := &BaseCtrl{make([]Filter, 0)}
	return ctrl
}

/**
 * 基础控制器
 */
type BaseCtrl struct {
	filters []Filter
}

func (ctrl *BaseCtrl) DoBefore(ctx *Context) error {
	return nil
}

func (ctrl *BaseCtrl) DoAfter(ctx *Context) error {
	return nil
}

func (ctrl *BaseCtrl) Action(ctx *Context) {
}

func (ctrl *BaseCtrl) AddFilter(filter Filter) {
	ctrl.filters = append(ctrl.filters, filter)
}

func (ctrl *BaseCtrl) Filters() []Filter {
	return ctrl.filters
}
